package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.*;

/**
 * 请求获取IP并存放
 * @author 陶肖寅
 * @version V1.0
 * @Package org.apache.dubbo.rpc.Filter
 * @email fromlx@126.com
 * @date 2020-04-16 23:03
 * @Copyright © 2020-2021 城云科技(中国)有限公司
 */
@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class TransportIPFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        RpcContext.getContext()
                .setInvocation(invocation)
                .setInvoker(invoker)
                .setLocalAddress(NetUtils.getLocalHost(),0)
                .setRemoteAddress(invoker.getUrl().getHost(),invoker.getUrl().getPort());
        return invoker.invoke(invocation);
    }
}
